package org.esk.dablog.web.forms.forum;

import org.esk.dablog.web.forms.ViewEntryForm;
import org.esk.dablog.model.Entry;
import org.esk.dablog.model.Comment;
import org.esk.dablog.ApplicationConstants;
import org.springframework.web.servlet.ModelAndView;
import org.apache.commons.lang.math.NumberUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * This class implements "View Forum Topic" task
 * User: esk
 * Date: Dec 12, 2006
 * Time: 3:04:25 PM
 * $Id:$
 */
public class ViewPostForm extends ViewEntryForm {
    private static final String PARAMETER_SKIP = "skip";


    protected void processEntry(HttpServletRequest request, HttpServletResponse response, ModelAndView modelAndView, Entry entry) {
        int start = NumberUtils.toInt(request.getParameter(PARAMETER_SKIP));
        int count = ApplicationConstants.getInstance().getDefaultPortion();
        List<Comment> comments = getEntryManager().listComments(entry, start, count);
        modelAndView.addObject("comments", comments);
        super.processEntry(request, response, modelAndView, entry);    //To change body of overridden methods use File | Settings | File Templates.
    }
}
